package com.itbaizhan.shopping_manager_api.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itbaizhan.shopping_common.pojo.Category;
import com.itbaizhan.shopping_common.result.BaseResult;
import com.itbaizhan.shopping_common.service.CategoryService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @DubboReference
    private CategoryService categoryService;

    @PostMapping("/add")
    public BaseResult add(@RequestBody Category category) {
        categoryService.add(category);
        return BaseResult.ok();
    }

    @PutMapping("/update")
    public BaseResult update(@RequestBody Category category) {
        categoryService.update(category);
        return BaseResult.ok();
    }

    @DeleteMapping("/delete")
    public BaseResult delete(Long[] ids) {
        categoryService.delete(ids);
        return BaseResult.ok();
    }

    @PutMapping("/updateStatus")
    public BaseResult putAway(Long id,Integer status) {
        categoryService.putAway(id, status);
        return BaseResult.ok();
    }

    @GetMapping("/findById")
    public BaseResult findById(Long id) {
        return BaseResult.ok(categoryService.findById(id));
    }

    @GetMapping("/search")
    public BaseResult<Page<Category>> search(int page,int size){
        return BaseResult.ok(categoryService.search(page,size));
    }
}
